package com.fsy.main;

import java.io.BufferedWriter;
import java.io.IOException;

/**
 * 联系人类
 * @author Sylvia
 *
 */
public class Person {
	private String name; //联系人名字
    private String telphone;//联系电话
    private String address;//通讯地址
    private String result; //写入文件的联系人
    
    /**
     * 构造方法，用来构造新的联系人
     * @param name 联系人姓名
     * @param Telphone 联系人号码
     * @param Address 联系人地址
     */
    public Person(String name,String Telphone,String Address){
        this.setName(name);
        this.setTelphone(Telphone);
        this.setAddress(Address);
    }
    
    
    public String getName() {
        return name; //获取联系人名字
    }
    public void setName(String name) {
        this.name = name;//设置联系人名字
    }
    public String getTelphone() {
        return telphone;//获取联系人电话
    }
    public void setTelphone(String telphone) {
        this.telphone = telphone;//设置联系人电话
    }
    public String getAddress() {
        return address;//获取联系人通讯地址
    }
    public void setAddress(String address) {
        this.address = address;//设置联系人通讯地址
    }
    
    /**
     * 
     * @param out 单个联系人的字符输入流
     */
    public void saveMe(BufferedWriter out){
        //需要指定输出对象
        try {
        	this.result = this.name +"|"+this.telphone+"|"+this.address;
            out.write(this.name +"|"+this.telphone+"|"+this.address); //按照格式保存联系人
            out.newLine();//在文件中写入新行
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("保存联系人时发生异常！");
            e.printStackTrace();
        }
         
         
    }
    
    /**
     * 生成新联系人的对象
     * @return Person对象
     */
    public Person getUpdatePerson(){
        //该方法的解决不是为了复制对象
        return new Person(this.name,this.telphone,this.address);
    }
    
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}

	public String toString() {
		return "Person [name=" + name + ", telphone=" + telphone + ", address=" + address + "]";
	}
	
	
}
